<?php $this->load->view('layout/header'); ?>
<div class="supplier-content-page">
    <div class="product-test-h5">
        <ul class="breadcrumb">
            <li><a href="javascript:;">营销管理</a></li>
            <li><a href="javascript:;">授信管理</a></li>
            <li  class="active"><a href="javascript:;">新用户授信</a></li>
        </ul>
        <div class="product-alls">
            <div class="product-fonter">添加</div>
            <form class="form-horizontal" action="<?php echo site_url('user_credit/addPost')?>" method="post" id="tourismtemplet_add">
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>被授信者</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control required user-name" placeholder="用户名或手机号">
                        <input type="hidden" name="uid" value="0">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>授信金额</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control number required" name="amount">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label">授信描述</label>
                    <div class="col-xs-6">
                        <input type="text" class="form-control" name="note">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-1 control-label"><em>* </em>状　　态</label>
                    <div class="col-xs-5">
                        <label class="radio-inline">
                            <input type="radio" name="status" value="1" checked="checked"> 启用
                        </label>
                        <label class="radio-inline">
                            <input type="radio" name="status" value="0"> 禁用
                        </label>
                    </div>
                </div>
                <div class="form-btn">
                    <a href="javascript:;">
                        <button class="btn btn-info" type="submit">保存</button>
                    </a>
                    <a href="<?php echo site_url('user_credit/grid');?>">返回上一步</a>
                </div>
            </form>
        </div>
    </div>
</div>
<?php $this->load->view('layout/footer'); ?>
<script type="text/javascript">
$(document).ready(function(){
	$('.form-horizontal').submit(function(){
        return false;
    }).validate({
        submitHandler: function(f) {
            var obj = $('button[type=submit]');
            $.ajax({
                type: 'post',
                async: false,
                dataType : 'json',
                url: hostUrl() + '/user_credit/addPost',
                data: $('form.form-horizontal').serialize(),
                beforeSend: function() {
                    obj.text('正在保存...').attr('disabled', true);
                },
                success: function(data) {
                    if (data.status) {
                        window.location.href = data.msg;
                    } else {
                        layerMessages(data.status, data.msg);
                    }
                    obj.text('重新保存').removeAttr('disabled');
                }
            });
        }
    });
    $('.user-name').change(function(){
    	$.ajax({
            type:'post',
            url:hostUrl()+'/user_credit/ajaxQueryId',
            data:{namephone:$(this).val()},
            async:false,
            dataType:'json',
            success:function(data) {
                if (data.status) {
                    $("[name='uid']").val(data.data.uid);
                } else {
                	$("[name='uid']").val(0);
                    layerMessages(data.status, data.msg);
                }
            }
         });
    });
});
</script>

